/**
* 资料认证管理  企业认证
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/index/mainAdmin' }">主页</el-breadcrumb-item>
      <el-breadcrumb-item>资料认证管理</el-breadcrumb-item>
      <el-breadcrumb-item>企业认证</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 搜索筛选 -->
    <el-form class="user-search">
      <el-form-item>
        <el-button size="small" type="primary" >审批列表</el-button>
      </el-form-item>
    </el-form>

    <!--列表-->
    <el-table size="small"  :data="companyData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" sortable prop="companyId" label="公司id" width="80">
      </el-table-column>
      <el-table-column align="center" sortable prop="companyFullName" label="公司名称" width="120">
      </el-table-column>
      <el-table-column align="center" sortable prop="companyAddress" label="公司地址" width="120">
      </el-table-column>
      <el-table-column align="center" sortable prop="companyCode" label="统一社会信用代码" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="legalName" label="企业法人姓名" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="capital" label="注册资金" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="commitTime" :formatter="formatDate" label="提交日期" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="borrowInfoStatus" :formatter="stateFormat" label="审批状态" width="100">
      </el-table-column>

      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="success" @click="handleEdit(scope.$index, scope.row)">审批</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <el-pagination class="page-box"   layout="total" :total="pageparm.total">
    </el-pagination>

    <!-- 编辑界面 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="40%" @click='closeDialog("edit")'>
      <el-form label-width="150px" ref="editForm" :model="editForm">
        <el-form-item label="公司名称" prop="companyFullName">
          <el-input :disabled="true" size="small" v-model="editForm.companyFullName" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="公司地址" prop="companyAddress">
          <el-input :disabled="true" size="small" v-model="editForm.companyAddress" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="companyCode">
          <el-input :disabled="true" size="small" v-model="editForm.companyCode" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="企业法人姓名" prop="legalName">
          <el-input :disabled="true" size="small" v-model="editForm.legalName" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="注册资金" prop="capital">
          <el-input :disabled="true" size="small" v-model="editForm.capital" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="审批状态" prop="borrowInfoStatus">
          <el-input :disabled="true" size="small" v-model="editForm.borrowInfoStatus" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="审批状态" prop="borrowInfoStatus">
          <el-radio v-model="editForm.borrowInfoStatus" label="1">审批中</el-radio>
          <el-radio v-model="editForm.borrowInfoStatus" label="2">审批通过</el-radio>
          <el-radio v-model="editForm.borrowInfoStatus" label="-1">未通过</el-radio>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click='closeDialog("edit")'>取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">保存</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
// 导入请求方法
export default {
  data() {
    return {
      loading: false, //是显示加载
      title: '企业认证',
      editFormVisible: false, //控制编辑页面显示与隐藏
      companyData:[],
      borrowInfoStatus:'',//审批状态
      // 编辑与添加
      editForm: {
        companyId: '',//公司id
        companyFullName: '',//公司名称
        companyAddress: '',//公司地址
        companyCode: '',//统一社会信用代码
        legalName: '',//企业法人姓名
        capital: '',//注册资金
        commitTime: '',//提交日期
        borrowInfoStatus: '',//审批状态
      },
      // 分页参数
      pageparm: {
        total: 10
      }
    }
  },

  /**
   * 创建完毕
   */
  created() {
    this.getdata()
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    getdata() {
      this.loading = true
      this.$axios
          .post(`http://localhost:9090/loan/company/getCompanyList`).then(
          response => {
            this.companyData = response.data;

            // 条数
            this.pageparm.total = this.companyData.length
            this.loading = false
          }
      )
    },
    stateFormat(row, column){
      if(row.borrowInfoStatus === "-1"){
        return '未通过'
      }else if (row.borrowInfoStatus === "2"){
        return '审核通过'
      }else {
        return '审核中'
      }
    },
    //input限制输入

    //日期转换
    formatDate(row, column) {
      // 获取单元格数据
      let data = row[column.property]
      if(data == null) {
        return null
      }
      let dt = new Date(data)
      return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds()
    },
    // 审批
    //显示编辑界面
    handleEdit: function(index, row) {
      console.log(row.borrowInfoStatus)
      if (row.borrowInfoStatus==1) {
        this.editFormVisible = true
        if (row != undefined && row != 'undefined') {
          this.title = '企业认证'
          this.editForm.companyId = row.companyId
          this.editForm.companyFullName = row.companyFullName
          this.editForm.companyAddress = row.companyAddress
          this.editForm.companyCode = row.companyCode
          this.editForm.legalName = row.legalName
          this.editForm.capital = row.capital
          this.editForm.commitTime = row.commitTime
          this.editForm.borrowInfoStatus = row.borrowInfoStatus

        }
      }
    },
    // 编辑、添加提交方法
    submitForm(editData) {
      this.$refs[editData].validate(valid => {
        if (valid) {
          // 请求方法
          this.$axios
              .post(`http://localhost:9090/loan/company/updateCompany`,this.$qs.stringify(this.editForm)).then(
              response => {
                this.editFormVisible = false
                this.loading = false
                if (response.data.success) {
                  this.getdata(this.formInline)
                  this.$message({
                    type: 'success',
                    message: '企业认证成功！'
                  })
                } else {
                  this.$message({
                    type: 'info',
                    message: "企业认证失败，请稍后再试！"
                  })
                }

              }
          ).catch(err => {
            this.editFormVisible = false
            this.loading = false
            this.$message.error('企业认证失败，请稍后再试！')
          })

        } else {
          return false
        }

      })
    },
    // 关闭编辑、增加弹出框
    closeDialog(dialog) {
      if (dialog == 'edit') {
        this.editFormVisible = false
      } else if (dialog == 'perm') {
        this.dataAccessshow = false
      } else if (dialog == 'unit') {
        this.unitAccessshow = false
      }
    },


  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

